import { BasePlugin } from "./BasePlugin";
import { ShellUtil } from "../util/ShellUtil";
import { ConfigUtil } from "../util/ConfigUtil";

export class PullServer extends BasePlugin {
    getName(): string {
        return "拉服务器";
    }    
    getDesc(): string {
        return "拉服务器 PullServer 平台名 测试或正式";
    }
    do(args: string[], cb:()=>void): void {
        let shName = "publish_client_debug";
        if (args[1] == "release") {
            shName = "publish_client";
        }
        let sshServer = ConfigUtil.PlatCfg[args[0]].sshServer;
        ShellUtil.exec(`
        ssh -tt ${sshServer.username}@${sshServer.host} -p ${sshServer.port} 'sudo bash /data/autodeploy/${shName}.sh'
        `, (log:string)=>{
            console.log("log", log);
            console.log("pull server ok");
            if (args[0] == "dev" && args[1] == "debug") {
                ShellUtil.exec(`
                ssh -tt ${sshServer.username}@${sshServer.host} -p ${sshServer.port} 'sudo bash /data/autodeploy/publish_luascripts.sh'
                `, (log:string)=>{
                    console.log("log", log);
                    cb();
                });
            } else {
                cb();
            }
        });
    }


}